package bawei.com.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import bawei.com.bilibili.R;
import bawei.com.model.bean.RecommendBean;

/**
 * 类描述:
 * 作者：张宏达
 * 时间:2017/3/9 15:55
 * 邮箱:18310832074@163.com
 */
public class RcmdAdapter extends RecyclerView.Adapter<MyViewHolder> {

    private LayoutInflater inflater;
    private Context mContext;
    private List<RecommendBean.DataBean> mDatas;

    //创建构造参数
    public RcmdAdapter(Context context, List<RecommendBean.DataBean> datas) {
        this.mContext = context;
        this.mDatas = datas;
        inflater = LayoutInflater.from(context);
    }

    //创建ViewHolder
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.recycleview_item, parent, false);
        MyViewHolder viewHolder = new MyViewHolder(view);
        return viewHolder;
    }

    //绑定ViewHolder
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        //为textview 赋值
        holder.name.setText(mDatas.get(position).getTitle());
      holder.play.setText(""+mDatas.get(position).getPlay());
        holder.title.setText(""+mDatas.get(position).getDanmaku());
       Glide.with(mContext).load(mDatas.get(position).getCover()).into(holder.imageView);
    }


    @Override
    public int getItemCount() {
        //Log.i("TAG", "mDatas "+mDatas);

        return mDatas.size();

    }

    //新增item
    public void addData(int pos) {
//        mDatas.add("新增");
        notifyItemInserted(pos);
    }

    //移除item
    public void deleateData(int pos) {
        mDatas.remove(pos);
        notifyItemRemoved(pos);
    }
}

class MyViewHolder extends RecyclerView.ViewHolder {

    TextView name, play, title;
    ImageView imageView;

    public MyViewHolder(View itemView) {
        super(itemView);
        imageView = (ImageView) itemView.findViewById(R.id.rcv_item_img);
        name = (TextView) itemView.findViewById(R.id.rcv_item_name);
        play = (TextView) itemView.findViewById(R.id.rcv_item_play);
        title = (TextView) itemView.findViewById(R.id.rcv_item_height);
    }
}
